/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-03-12
 * Time: 20:55
 */
public class Main {
    public int longestOnes1(int[] nums, int k) {
        int left = 0,right = 0,n = nums.length;
        int zero = 0;
        int count = 0;
        while (right < n){
            if (nums[right] == 0){
                zero++;
            }
            while (zero > k){
                if (nums[left] == 0){
                    zero--;
                }
                left++;
            }
            count = Math.max(count,right-left+1);
            right++;
        }
        return count;
    }

    public int longestOnes(int[] nums, int k) {
        int ret = 0;
        for (int left = 0,right = 0,zero = 0; right < nums.length; right++) {
            if (nums[right] == 0){
                zero++;//进窗口
            }
            while (zero > k){ //判断
                if (nums[left++] == 0){
                    zero--;
                }
            }
            ret = Math.max(ret,right - left + 1);
        }
        return ret;
    }
}
